package com.baizan.daka.mvp.model

import com.baizan.daka.mvp.model.bean.*
import com.baizan.daka.net.BasePageResponse
import com.baizan.daka.net.bean.*
import com.baizan.daka.util.SchedulerUtils
import com.hazz.kotlinmvp.net.BaseResponse
import com.hazz.kotlinmvp.net.RetrofitManager
import io.reactivex.Observable
import rx.functions.ActionN

class UserModel {

    fun passwordQuestion():Observable<BaseResponse<List<QuestionBean>>> =
        RetrofitManager.service.passwordQuestion()
            .compose(SchedulerUtils.ioToMain())

    fun modifyPassword(mobile:String,oldPassword:String,newPassword:String): Observable<BaseResponse<Any>> {
        val map = HashMap<String, String>()
        map.put("mobile",mobile)
        map.put("newPassword",newPassword)
        map.put("oldPassword",oldPassword)
        return RetrofitManager.service.modifyPassword(map)
            .compose(SchedulerUtils.ioToMain())
    }
    fun findPassword(registBean: FindPasswordBean): Observable<BaseResponse<Any>> {
        return RetrofitManager.service.findPassword(registBean)
            .compose(SchedulerUtils.ioToMain())
    }

    fun loginOut(): Observable<BaseResponse<Any>> {
        val map = HashMap<String, String>()
        return RetrofitManager.service.logout(map)
            .compose(SchedulerUtils.ioToMain())
    }

    fun login(account: String, password: String): Observable<BaseResponse<LoginInfoBean>> {

        return RetrofitManager.service.login(
                LoginRequestBean(account, password, "password")
            )
            .compose(SchedulerUtils.ioToMain())
    }

    fun registerCode(phone: String): Observable<BaseResponse<RegistInfoBean>> {

        return RetrofitManager.service.getRegistCode(
            SendCodeRequestBean(phone)
        ).compose(SchedulerUtils.ioToMain())
    }

    fun register(registBean: RegistBean): Observable<BaseResponse<String>> {

        return RetrofitManager.service.regist(registBean)
            .compose(SchedulerUtils.ioToMain())
    }

    fun modify(modifyUserBean: ModifyUserBean): Observable<BaseResponse<String>> {
        return RetrofitManager.service.modifyUser(modifyUserBean)
            .compose(SchedulerUtils.ioToMain())
    }

    fun getUserInfo(): Observable<BaseResponse<UserInfoBean>> {
        return RetrofitManager
            .service
            .getUserInfo()
            .compose(SchedulerUtils.ioToMain())
    }

    fun getVipList(
        pageNo: Int,
        usedFlag: Int?
    ): Observable<BaseResponse<BasePageResponse<PakeageInfoBean>>> {
        val param = BasePageParam<UserVipsRequestBean>(pageNo, UserVipsRequestBean(usedFlag))
        return RetrofitManager
            .service
            .userPackageList(param)
            .compose(SchedulerUtils.ioToMain())
    }

    fun getPublishTaskList(
        pageNo: Int,
        taskStatus: Int?
    ): Observable<BaseResponse<BasePageResponse<TaskInfoBean>>> {
        val param = BasePageParam<UserPublishTaskRequestBean>(
            pageNo,
            UserPublishTaskRequestBean(taskStatus)
        )
        return RetrofitManager
            .service
            .publishTaskList(param)
            .compose(SchedulerUtils.ioToMain())
    }
}